package com.ghy.text;

import com.ghy.entity.EbUser;
import com.ghy.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

//导入 spring 的单元测试
@RunWith(SpringJUnit4ClassRunner.class)
// 导入 spring 的配置文件
@ContextConfiguration("classpath:xml/spring-web.xml")
public class UserTest {
    @Autowired
    UserMapper userMapper;

    @Test
    public void testUserPage() {
        int page = 1;//查询第 1 页
        int pageSize= 3;//每页 3 条
        // alt+Enter
        List<EbUser> user = userMapper.findByPage((page - 1) * pageSize, pageSize);
        System.out.println(user);
    }

    @Test
    public void testUserSave() {
        EbUser enUser = new EbUser();
        enUser.setEuUserId("504");
        enUser.setEuUserName("阿敏");
        enUser.setEuPassword("aaa");
        enUser.setEuSex("T");
        enUser.setEuAddress("湖南省永州市冷水滩");
        enUser.setEuStatus(1);
        int result = userMapper.save(enUser);
        System.out.println("result-:" + result);
    }
    @Test
    public void testUserDelete(){
        int result = userMapper.remove("504");
        System.out.println("result:"+result);
    }


    @Test
    public void testUserUpdate(){
        EbUser enUser = new EbUser();
        enUser.setEuUserId("2020");
        enUser.setEuUserName("阿敏");
        //调用更新的方法
        int result = userMapper.updateByPrimaryKey(enUser);
        System.out.println("result:"+result);

    }

}